package com.yt.al.config;

import io.appium.java_client.AppiumDriver;

import java.io.File;
import java.net.URL;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.yt.al.util.WriteLogUtil;

public class SWGJDriver {
	public static AppiumDriver returnDriver() {

		return returnDriver("http://127.0.0.1:4723/wd/hub");
	}

	public static AppiumDriver returnDriver(String url, String udid) {
		if(url.equals(""))
		{
			url = "http://127.0.0.1:4723/wd/hub";
		}
		AppiumDriver driver = null;
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("platformName", BaseConfig.platformName);
		capabilities.setCapability("deviceName", BaseConfig.deviceName);
		if (udid != null && !udid.equals("")) {
			capabilities.setCapability("udid", udid);
		}

		capabilities.setCapability(CapabilityType.VERSION,
				BaseConfig.platformVersion);
		capabilities.setCapability("newCommandTimeout", "60");
		capabilities.setCapability("appPackage", "com.sunbelt.androidbutler");
		capabilities.setCapability("appActivity",
				"com.sunbelt.androidbutler.app.activity.GuidePageActivity");
		try {
			driver = new AppiumDriver(new URL(url), capabilities);
		} catch (Exception e) {
			e.printStackTrace();
			WriteLogUtil.writeMsgToFile("returnDriver�쳣:" + e);
		}
		return driver;
	}

	public static AppiumDriver returnDriver(String url) {
		return returnDriver(url, null);
	}
}
